<!-- 专家抽取页面 -->
<template>
    <div class="app-container">
        <el-button @click="extractExpert" type="primary" v-show="this.$route.query.status == 4">抽取专家</el-button>
        <!-- this.$route.query.status==2||this.$route.query.status==3|| -->
        <div style="margin-bottom: 20px;"></div>

        <el-table :data="tableData" stripe style="width: 100%" v-loading="loading">
            <el-table-column label="序号" type="index" align="center" width="50">
            </el-table-column>
            <el-table-column prop="pbName" label="姓名" align="center">
            </el-table-column>
            <el-table-column prop="pbSex" label="性别" align="center" :formatter="sexFormatter">
            </el-table-column>
            <el-table-column prop="pbIdCard" label="身份证号" align="center">
            </el-table-column>
            <el-table-column prop="pbPhone" label="联系方式" align="center">
            </el-table-column>
            <el-table-column label="操作" align="center">
                <template sloat-scope="scope">
                    <el-button type="primary" size='mini' @click="deleteRow(scope.row)" plain>删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script>
import { committeeList, deletecommittee, getStartTimeAndEndTime, getTenderStatusTime } from '@/api/system/purchase'

export default {
    data() {
        return {
            iNumber: '',
            tableData: [],
            loading: true,
            total: 0,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                iNumber: ''
            }
        }
    },
    methods: {
        //专家抽取
        extractExpert() {
            const currentTime = new Date();
            if (currentTime < new Date(this.$route.query.kaiStartTime) || currentTime > new Date(this.$route.query.kaiEndTime)) {
                this.$message.error('不在开标期内!');
                return false;
            }
            this.$router.push({ path: '/tender/expertSelection', query: { iNumber: this.$route.query.iNumber } })
        },
        getStartTimeAndEndTime() {
            getStartTimeAndEndTime(this.queryParams.iNumber).then(res => {
                console.log(res, "撒旦发生的发");

                if (res.data != null) {
                    this.$route.query.startTime = res.data.startTime;
                    this.$route.query.endTime = res.data.endTime;
                }
            })
        },
        //评标委员会获取
        getList() {
            committeeList(this.queryParams).then(res => {
                console.log("this.getList",res);
                this.loading = false;
                this.tableData = res.rows;
                this.total = res.total;
            })
        },
        deleteRow(row) {
            this.$confirm('是否确定删除, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                deletecommittee(row.jId).then(() => {
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        sexFormatter(row, column, cellValue, index) {
            if (cellValue == 1) {
                return '男';
            } else {
                return '女';
            }
        },
        //专门为了获取状态和时间
        getTenderStatusTime(iNumber) {
            getTenderStatusTime(iNumber).then(res => {
                //这样设置,是因为之前采用的是路由传承,后面发现刷新不到最新值(其实每个下面mounted都有了这些值,但是最初判断并没有使用这个方法,所以为路由赋值)
                this.$route.query.status = res.data.status;
                const data=res.data;
                if (data.startTime) {
                    this.$route.query.startTime = res.data.startTime
                }
                if (data.endTime) {
                    this.$route.query.endTime = res.data.endTime
                }
                if (data.kaiStartTime) {
                   this.$route.query.kaiStartTime = res.data.kaiStartTime;
                }
                if (data.kaiEndTime) {
                    this.$route.query.kaiEndTime = res.data.kaiEndTime;
                }
                if (data.getStartTime) {
                    this.$route.query.getStartTime = res.data.getStartTime
                }
                if (data.getEndTime) {
                    this.$route.query.getEndTime = res.data.getEndTime
                }
            })
        },
    },
    mounted() {
        this.queryParams.iNumber = this.$route.query.iNumber
        this.getList();
        this.getStartTimeAndEndTime();
        this.getTenderStatusTime(this.queryParams.iNumber);
    },

}
</script>
<style scoped></style>